home *** CD-ROM | disk | FTP | other *** search
- #
- # GlobalObjects.py
- # JunkMatcher
- #
- # Created by Benjamin Han on 2/1/05.
- # Copyright (c) 2005 Benjamin Han. All rights reserved.
- #
-
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # of the License, or (at your option) any later version.
-
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
-
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- #!/usr/bin/env python
-
- from consts import *
- from utilities import *
-
-
- def loadSafeSitesPattern ():
- lines = openFile('%ssafeSites' % CONF_PATH).readlines()
- if len(lines):
- return re.compile(r'|'.join([r'(?:%s)'%l.strip() for l in lines]), re.IGNORECASE)
- else: return None
-
-
- class GlobalObjects (object):
- """Storing all global objects that need to be reloaded at some point, and
- do lazy initialization."""
- def __init__ (self):
- self.emailDBReadFlag = False
-
- def emailAddrPat (self):
- # Email address/comment pattern according to RFC 2822
- return re.compile(''.join(map(lambda l:l.rstrip(), open('%setc/rfc2822' % ENGINE_PATH))))
- emailAddrPat = Lazy(emailAddrPat)
-
- def emailAddrCommentPat (self):
- return re.compile('[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*')
- emailAddrCommentPat = Lazy(emailAddrCommentPat)
-
- def prefs (self):
- return __import__('Preferences').Preferences('%sprefs' % CONF_PATH)
- prefs = Lazy(prefs)
-
- def htmlTags (self):
- return __import__('HTMLTagDict').HTMLTagDict('%shtmlTags' % CONF_PATH)
- htmlTags = Lazy(htmlTags)
-
- def safeSitesPattern (self):
- return loadSafeSitesPattern()
- safeSitesPattern = Lazy(safeSitesPattern)
-
- def siteDB (self):
- return __import__('SiteDB').SiteDB('%ssiteDB' % CONF_PATH, self.prefs.siteLimit)
- siteDB = Lazy(siteDB)
-
- def recipientPatterns (self):
- return __import__('SimplePatterns').SimplePatterns('%srecipientPatterns' % CONF_PATH)
- recipientPatterns = Lazy(recipientPatterns)
-
- def safeIPs (self):
- return __import__('SimplePatterns').SimplePatterns('%ssafeIPs' % CONF_PATH)
- safeIPs = Lazy(safeIPs)
-
- def whitelist (self):
- return __import__('SimplePatterns').SimplePatterns('%swhitelist' % CONF_PATH, True)
- whitelist = Lazy(whitelist)
-
- def metaPatterns (self):
- return __import__('MetaPatterns').MetaPatterns('%smetaPatterns' % CONF_PATH)
- metaPatterns = Lazy(metaPatterns)
-
- def addressSet (self):
- return __import__('addressBook').getAddressesFromABook()
- addressSet = Lazy(addressSet)
-
- def logger (self):
- return __import__('Logger').Logger('%sjm.log' % CONF_PATH)
- logger = Lazy(logger)
-
- def emailDB (self):
- return __import__('EmailDB').EmailDB('%semailDB.dat' % CONF_PATH, self.emailDBReadFlag)
- emailDB = Lazy(emailDB)
-
-
- globalObjects = GlobalObjects()
-
-
- if __name__ == '__main__':
- print globalObjects.addressSet
-